/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sort;

/**
 *
 * @author BDSHADOW
 */
public class Sort {
    public static void main(String[] args) {
        BigReadWrite data = new BigReadWrite();
        int[] a = data.readArray(args[0]);
        mergesort(a, 0, a.length-1);
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
        data.writeArray(a, args[1]);
    }
    
     private static void mergesort (int[] a, int low, int high) { 
          if (low < high) {
              int m = (low+high)/2; 
              mergesort (a, low, m); 
              mergesort (a, m+1, high); 
              merge (a, low, m, high);
          }
     } 

     private static void merge (int[] a, int low, int m, int high) { 
          if (m+1>high) return; 
          int[] b = new int[a.length]; 
          for (int i=low; i!=m+1; i++) { 
               b[i] = a[i]; 
          } 

          for (int i=m+1; i!=high+1; i++) { 
               b[i] = a[high+m+1-i]; 
          }

          int k=low; int j=high;
          for (int i=low; i!=high+1; i++) { 
               if (b[k] <= b[j]) {
                   a[i] = b[k++];
               } else {
                    a[i] = b[j--];
               }
          } 
     }
}
